<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once "class/Load.class.php";
require_once "class/WowTable.class.php";
require_once "class/Config.class.php";
require_once "class/Inputs.class.php";
require_once "class/StatusRoster.class.php";
require_once "class/Localization.class.php";
require_once "class/DungeonContainer.class.php";
require_once "class/DungeonDisplayer.class.php";
require_once "class/DungeonCategoryContainer.class.php";
require_once "class/CharacterManager.class.php";
require_once "class/CharacterDisplayer.class.php";

$load = Load::GetInstance();
$config = Config::GetInstance();
$inputs = Inputs::GetInstance();
$localization = Localization::GetInstance();
$status_roster = StatusRoster::GetInstance();
$dungeon_container = DungeonContainer::GetInstance();
$dungeon_displayer = DungeonDisplayer::GetInstance();
$dungeon_category_container = DungeonCategoryContainer::GetInstance();
$character_manager = CharacterManager::GetInstance();
$character_displayer = CharacterDisplayer::GetInstance();

if ( $dungeon_category_container->HasCategory($inputs->Get('c')) )
{
	$wow_table = new WowTable( $dungeon_category_container->GetCategory($inputs->Get('c'))->GetName() );
	$wow_table->AddSubSection();
	$wow_table->AddColumn($localization->Get('name'));
	
	foreach ($dungeon_container->GetDungeons() as $dungeon)
	{
		if ( $dungeon_category_container->GetCategory($inputs->Get('c'))->IsInCategory($dungeon) )
		{
			$wow_table->AddColumn(
				"<img src='img/".$dungeon->GetIcon()."' alt='' /><br />".$dungeon->GetName(),
				"center",
				120,
				true
			);
		}
	}
	
	foreach($character_manager->GetAllCharactersWithDungeonsAccess() as $character)
	{
		$t_character = array(
			$character_displayer->Name($character)
		);
		
		foreach ($dungeon_container->GetDungeons() as $dungeon)
		{
			if ( $dungeon_category_container->GetCategory($inputs->Get('c'))->IsInCategory($dungeon) )
			{
				if ( $character->HasDungeonAccess($dungeon->GetId()) )
				{
					array_push($t_character, $dungeon_displayer->Access(true));
				}
				else
				{
					array_push($t_character, $dungeon_displayer->Access(false));
				}
			}
		}
		
		$wow_table->AddLine(0, $t_character);
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
	<head>
		<title>LZRoster<?php echo $config->HasRosterTitle() ?  " - ".$config->GetRosterTitle() : null; ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/_.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/wowtable.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/dungeons.css" />
		<script type="text/javascript" src="js/overlib.js"><!-- overLIB (c) Erik Bosrup --></script>
	</head>
	<body>
		
		<?php require_once "inc/head.php"; ?>
		<?php require_once "inc/hmenu.php"; ?>
		
		<p id="dungeonmenu">
			<?php echo $localization->Get('choose'); ?>
			
			<?php
			foreach ( $dungeon_category_container->GetCategories() as $dungeon_category )
			{
			?>
			
			<img src="img/<?php echo $dungeon_category->GetIcon(); ?>" alt="" /> <a href="?c=<?php echo $dungeon_category->GetId(); ?>"><?php echo $dungeon_category->GetName(); ?></a>
			
			<?php
			}
			?>
			
		</p>
		
		<?php
		if ($status_roster->HasMessage())
		{
		?>
			
			<p>
				<?php echo $localization->Get('this page produced some messages. please refer to the following lines'); ?>
			</p>
			
			<?php echo $status_roster->GetStack_InList(); ?>
			
			<p>
				<?php echo $localization->Get('you can refresh the page %s and try again', "dungeons.php"); ?>
			</p>
			
		<?php
		}
		elseif (isset($wow_table))
		{
		?>
		
		<h2>
			<img src="img/<?php echo $dungeon_category_container->GetCategory($inputs->Get('c'))->GetBigIcon(); ?>" alt="" style="vertical-align: middle;" />
			<?php echo $localization->Get('dungeons access'); ?>
			(<?php echo $dungeon_category_container->GetCategory($inputs->Get('c'))->GetName(); ?>)
		</h2>
		
		<?php $wow_table->GetAndPrintTable(); ?>
		
		<?php
		}
		?>
		
		<?php require_once "inc/foot.php"; ?>
		
	</body>
</html>